//
//  MapTouchTestView.m
//  SFU_BizMAPP
//
//  Created by Administrator on 11/8/10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "MapTouchTestView.h"


@implementation MapTouchTestView

@synthesize touchView;
@synthesize isActive;


- (id)initWithMapView:(MapViewController*)theMapView {
    if ((self = [super initWithFrame:theMapView.view.frame])) {
        mapView = theMapView;
		isActive = NO;
		//[self addSubview:theMapView];
    }
    return self;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (void)touchedAtPoint:(CGPoint)touchPoint {
	if (isActive) {
		[mapView showPinAtCoord:[mapView.mapView convertPoint:touchPoint 
										 toCoordinateFromView:mapView.mapView]];
	}
	//NSLog(@"%f, %f, %f, %f", lat1, long1, lat2, long2);
	//NSLog(@"> %f, %f", touchPoint.x, touchPoint.y);
}

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
	//[mapView hitTest:point withEvent:event];
    //NSLog(@"Hit Test");
	/*double lat1 = mapView.region.center.latitude - mapView.region.span.latitudeDelta/2;
	double long1 = mapView.region.center.longitude - mapView.region.span.longitudeDelta/2;
	double lat2 = mapView.region.center.latitude + mapView.region.span.latitudeDelta/2;
	double long2 = mapView.region.center.longitude + mapView.region.span.longitudeDelta/2;
	NSLog(@"%lli, %lli, %lli, %lli", lat1, long1, lat2, long2);
	*/
	NSLog(@"> %lli, %lli", point.x, point.y);
    touchView = [super hitTest:point withEvent:event];
    return self;
}


- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    NSLog(@"Touch Began");
    //[touchView touchesBegan:touches withEvent:event];
	//[mapView touchesBegan:touches withEvent:event];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    NSLog(@"Touch Moved");
    //[touchView touchesMoved:touches withEvent:event];
	//[mapView touchesMoved:touches withEvent:event];
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    //NSLog(@"Touch Ended");
    //[touchView touchesEnded:touches withEvent:event];
	//[mapView touchesEnded:touches withEvent:event];
}

- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
	//[mapView touchesCancelled:touches withEvent:event];
	//[touchView touchesCancelled:touches withEvent:event];
    NSLog(@"Touch Cancelled");
}


- (void)dealloc {
	[touchView release];
	touchView = nil;
	mapView = nil;
    [super dealloc];
}


@end
